package com.grp6.game.ui.platform.text.ansi;

import com.grp6.game.ui.platform.IAbstractUIPlatformFactory;
import com.grp6.game.ui.platform.ICell;
import com.grp6.game.ui.platform.IDialog;

public class AnsiTextConsoleFactory implements IAbstractUIPlatformFactory{
	private ColorPrinter printer;
	private UICellMapper cellMapper;
	
	public UICellMapper getUICellMapper(){
		if (cellMapper == null)
			cellMapper = new UICellMapper();
		return cellMapper;
	}
	public void setUICellMapper(UICellMapper cellMapper){
		this.cellMapper = cellMapper;
	}
	
	public ColorPrinter getColorPrinter(){
		if (printer == null){
			printer = new ColorPrinter(System.out);
			printer.reset().rewind();
		}
		return printer;
	}
	public void setColorPrinter(ColorPrinter printer){
		this.printer = printer;
	}
	
	
	@Override
	public ICell createICell(int x, int y) {
		cleanUp();
		return new AnsiCharacterCell(x,y,getColorPrinter(),getUICellMapper());
	}

	@Override
	public IDialog createIDialog() {
		cleanUp();
		return new AnsiCharacterDialog(getColorPrinter());
	}
	@Override
	public void cleanUp() {
		getColorPrinter().reset().rewind();
	}
}
